public class WinningPrice {

    private double chance;
    private int playTime;
    private int N;

    public WinningPrice(double chance, int playTime, int N) {
        if (chance < 0.0 || chance > 1.0 || playTime <= 0 || N <= 0) {
            throw new IllegalArgumentException("参数错误！");
        }

        this.chance = chance;
        this.playTime = playTime;
        this.N = N;
    }

    public void run() {
        int wins = 0;
        for (int i = 0; i < N; i ++) {
            if (play()) {
                wins ++;
            }
        }
        System.out.println("中奖率：" + ((double) wins / N));
    }

    private boolean play() {
        for (int i = 0; i < playTime; i ++) {
            if (Math.random() < chance) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        double chance = 0.2;
        int playTime = 5;
        int N = 1000000;

        WinningPrice wp = new WinningPrice(chance, playTime, N);
        wp.run();
    }
}
